package com.situ.mall.common.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.mall.common.entity.Cart;
import com.situ.mall.common.mapper.CartMapper;
import com.situ.mall.common.service.ICartService;
import com.situ.mall.common.vo.CartVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lwj
 * @since 2023-09-16
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {

    @Override
    public Cart selectByPId(Integer pId,Integer mId) {
        return baseMapper.selectByPId(pId,mId);
    }

    @Override
    public void deleteOne(Integer pId,Integer mId) {
        baseMapper.deleteOne(pId,mId);
    }

    @Override
    public void addOne(Integer pId, Integer mId) {
        Cart cart = baseMapper.selectByPId(pId, mId);
        int newAmount = cart.getAmount() + 1;
        baseMapper.addOne(pId,mId,newAmount);
    }

    @Override
    public void reduceOne(Integer pId, Integer mId) {
        Cart cart = baseMapper.selectByPId(pId, mId);
        int newAmount = cart.getAmount() - 1;
        baseMapper.reduceOne(pId,mId,newAmount);
    }

    @Override
    public CartVO select1(Integer mId, Integer cid) {
        return baseMapper.select1(mId,cid);
    }

    @Override
    public List<CartVO> select(Integer mId) {
        List<CartVO> list= baseMapper.select(mId);

        return list;
    }
    @Override
    public List<CartVO> select2(Integer mId,Integer cId) {
        return baseMapper.select2(mId,cId);
    }



}
